package com.gitee.lambda.file;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;

/**
 * 文件服务类
 *
 * @author gcq
 * @Create 2022-06-27
 */
public class FileService {

    public void fileHandler(String url, FileConsumer fileConsumer) throws Exception {
        // 创建文件读取流
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(new FileInputStream(url)));

        // 定义行变量和内容
        String line;
        StringBuffer stringBuffer = new StringBuffer();

        // 循环读取内容
        while((line = bufferedReader.readLine()) != null) {
            stringBuffer.append(line + "\n");
        }

        // 调用函数式接口方法
        fileConsumer.fileHandler(stringBuffer.toString());
    }
}